package com.zheng.study.base.bean.search.rule;

import org.hibernate.criterion.MatchMode;
import org.hibernate.type.Type;

import java.util.Collection;

/**
 * 查询 - 参数 - Rule 帮助类
 * ============================================================================
 * author : fallenpanda
 * createDate:  2018/6/11 。
 * ============================================================================
 */
public class RuleHelper {

	/**
	 * and关系
	 */
	public static Rule and(Rule... rules){
		return RuleRelation.and(rules);
	}

	/**
	 * or关系
	 */
	public static Rule or(Rule... rules){
		return RuleRelation.or(rules);
	}

	/**
	 * 为空
	 */
	public static Rule isEmpty(String field) {
		return RuleNone.isEmpty(field);
	}

	/**
	 * 不为空
	 */
	public static Rule isNotEmpty(String field) {
		return RuleNone.isNotEmpty(field);
	}

	/**
	 * 为空
	 */
	public static Rule isNull(String field) {
		return RuleNone.isNull(field);
	}

	/**
	 * 不为空
	 */
	public static Rule isNotNull(String field) {
		return RuleNone.isNotNull(field);
	}

	/**
	 * 等于
	 */
	public static Rule eq(String field, Object data) {
		return RuleSimple.eq(field, data);
	}

	/**
	 * 不等于
	 */
	public static Rule ne(String field, Object data) {
		return RuleSimple.ne(field, data);
	}

	/**
	 * 大于
	 */
	public static Rule gt(String field, Object data) {
		return RuleSimple.gt(field, data);
	}

	/**
	 * 大于等于
	 */
	public static Rule ge(String field, Object data) {
		return RuleSimple.ge(field, data);
	}

	/**
	 * 小于
	 */
	public static Rule lt(String field, Object data) {
		return RuleSimple.lt(field, data);
	}

	/**
	 * 小于等于
	 */
	public static Rule le(String field, Object data) {
		return RuleSimple.le(field, data);
	}

	/**
	 * 之内
	 */
	public static Rule in(String field, Object[] data) {
		return RuleSimple.in(field, data);
	}

	/**
	 * 之内
	 */
	public static Rule in(String field, Collection data) {
		return RuleSimple.in(field, data);
	}

	/**
	 * 模糊查询
	 */
	public static Rule like(String field, Object data) {
		if (data instanceof String) data = "%" + data + "%";
		return RuleLike.like(field, data);
	}

	/**
	 * 模糊查询
	 */
	public static Rule like(String field, String data, MatchMode matchMode) {
		return RuleLike.like(field, data, matchMode);
	}

	/**
	 * 模糊查询（忽略大小写）
	 */
	public static Rule ilike(String field, Object data) {
		if (data instanceof String) data = "%" + data + "%";
		return RuleLike.ilike(field, data);
	}

	/**
	 * 模糊查询（忽略大小写）
	 */
	public static Rule ilike(String field, String data, MatchMode matchMode) {
		return RuleLike.ilike(field, data, matchMode);
	}

	/**
	 * sql 条件（当前表 别名 {alias} / this_）
	 */
	public static Rule sql(String sql) {
		return RuleSql.sql(sql);
	}

	/**
	 * sql 条件（当前表 别名 {alias} / this_）
	 */
	public static Rule sql(String sql, Object[] values, Type[] types) {
		return RuleSql.sql(sql, values, types);
	}

}
